package structs;

import java.util.ArrayList;
import interfaces.ICard;
import interfaces.IDeck;

public class Deck implements IDeck {

	private ArrayList<ICard> cards = new ArrayList<ICard>();
	private int size = 0;
	private ICard life;
	
	public Deck(){		
		for(int i = 1; i<=12; i++){
			if(i > 7 && i < 10){
				//nothing
			}
			else {
				if(i==1){
					this.cards.add(new Card("B",i,11));
					this.cards.add(new Card("O",i,11));
					this.cards.add(new Card("C",i,11));
					this.cards.add(new Card("E",i,11));
				}
				else if(i==3){
					this.cards.add(new Card("B",i,10));
					this.cards.add(new Card("O",i,10));
					this.cards.add(new Card("C",i,10));
					this.cards.add(new Card("E",i,10));
				}
				else if(i==12){
					this.cards.add(new Card("B",i,4));
					this.cards.add(new Card("O",i,4));
					this.cards.add(new Card("C",i,4));
					this.cards.add(new Card("E",i,4));
				}
				else if(i==11){
					this.cards.add(new Card("B",i,3));
					this.cards.add(new Card("O",i,3));
					this.cards.add(new Card("C",i,3));
					this.cards.add(new Card("E",i,3));
				}
				else if(i==10){
					this.cards.add(new Card("B",i,2));
					this.cards.add(new Card("O",i,2));
					this.cards.add(new Card("C",i,2));
					this.cards.add(new Card("E",i,2));
				}
				else{
					this.cards.add(new Card("B",i,0));
					this.cards.add(new Card("O",i,0));
					this.cards.add(new Card("C",i,0));
					this.cards.add(new Card("E",i,0));
				}

			}
		}
		
		this.size = this.cards.size();
	}
	
	public Deck(ICard card){
		//Create Deck without card
	}
	
	public ICard getCard(String suit, int num) {
		for(ICard card : this.cards){
			if(card.getSuit().compareToIgnoreCase(suit) == 0 && card.getNumber() == num){
				return card;
			}
		}
		
		return null;
	}

	public ICard removeCard(String suit, int num) {
		int toDel = 0;
		boolean found = false;
		
		for(ICard card : this.cards){
			if(card.getSuit().equalsIgnoreCase(suit) && card.getNumber() == num){
				found = true;
				break;
			}
			toDel++;
		}
		
		if(found){
			return this.cards.remove(toDel);
		}
		
		return null;
	}

	public void addCard(ICard card){
		this.cards.add(card);
	}
	
	public ArrayList<ICard> getCards() {
		return this.cards;
	}

	public ArrayList<ICard> getCards(int num) {
		ArrayList<ICard> tempReturn = new ArrayList<ICard>();
		
		for(ICard card : this.cards){
			if(card.getNumber() == num){
				tempReturn.add(card);
			}
		}
		
		return tempReturn;
	}

	public ArrayList<ICard> getCards(String suit) {
		ArrayList<ICard> tempReturn = new ArrayList<ICard>();
		
		for(ICard card : this.cards){
			if(card.getSuit() == suit){
				tempReturn.add(card);
			}
		}
		
		return tempReturn;
	}

	public int cardsLeft() {
		return this.cards.size();
	}
	
	public int getSize(){
		return this.size;
	}
	
	public void setLife(ICard card){
		this.life = card;
	}
	
	public ICard getLife(){
		return this.life;
	}
	
}
